/*Author: Ilana M Ventura														  */
/*Date: September 2024															  */
/*Step 6: Table S4. Unweighted Counts of SOR Write-in�s by Type 				  */


/****Step 5: Table S4. Unweighted Counts of SOR Write-in�s by Type***/
proc freq data= sl_dat;
	where f2a_8_t ne "__NA__";
	table 
		f2a_8_t f2a_8_t *hisp*White*Asian*SOR*Black*AmIndAN*NHoPI*MENA
		 / list missing norow nocol;
run;

proc freq data= sl_dat;
	where f2b_15_t ne "__NA__";
	table  f2b_15_t f2b_15_t*hisp*White*Asian*Black*AmIndAN*NHoPI*MENA / list missing norow nocol;
run;


*Code 2020 as Hisp write in or not;
Data sl_dat_backcode;
	set sl_dat;
	if f2a_8_t ne "__NA__" then do;
		if f2a_8_t = "" then SOR_Blank=1;
		else if f2a_8_t = 'American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'American Puerto Rican Arawak Taino Indian' then SOR_Hisp_Ind=1 ;
		else if f2a_8_t = 'Armenian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Armenian and Indian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Ashkenazi' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Ashkenazi' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Brazilian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Cantaloupe' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Caribbean' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Caribbean' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Caribbean' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Caucasian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Caucasian, German French' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Cherokee Indian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Creole' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Eastern European' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Filipino' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Foundational Black American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Greek' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Greek and Polish' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Greek, Spanish, Egyptian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'HUMAN' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Hebrew' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Hindu' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Homo sapien' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Homo sapiens' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Hong Konger' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Human' then SOR_nonHisp=1  ;
		else if f2a_8_t = "Human, there's only one race, lots of ethnicity, based on geography" then SOR_nonHisp=1  ;
		else if f2a_8_t = 'I am no longer willing to be identified by race' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Indigenous' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Indigenous South American' then SOR_Hisp_Ind=1 ;
		else if f2a_8_t = 'Italian American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Italian, Jewish and Lithuanian' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Jewish' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Jewish' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Jewish (European/Ashkenazi)' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Jewish American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Meat Popsicle' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Mediterranean' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Mixed' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Mixed American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Mixed Racial Background: French, Cura�ao, West Indian plus a touch of Jewish, Dutch, and East African Ancestry' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Mixed race' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Mixed race Filipino Irish' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Multiethnic Human' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Multiracial' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Native/White' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'None' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'None' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Peruvian Indigenous' then SOR_Hisp_Ind=1 ;
		else if f2a_8_t = 'Portuguese' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Portuguese' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Slavic' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Son of Adam, Human, made in God�s image_' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'This is offensive!' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Turkish' then SOR_nonHisp=1  ;
		else if f2a_8_t = "Turkish, this depends on how far back you want on my family tree or dna results (which differ a good deal...)" then SOR_nonHisp=1  ;
		else if f2a_8_t = 'United States American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'White American' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'Yaqui and Seri Mexican indigenous' then SOR_Hisp_Ind=1 ;
		else if f2a_8_t = 'american made' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'human' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'human' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'human race' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'mix' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'mixed' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'mixed' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'othr' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'portuguese' then SOR_nonHisp=1  ;
		else if f2a_8_t = 'racist question' then SOR_nonHisp=1  ;	
		else if 	SOR_Blank= . and SOR_nonHisp=.
			and SOR_Hisp_Ind=. then SOR_Hisp=1;	
			end;
	
	if f2b_15_t ne "__NA__" then do;
		if f2b_15_t = "" then SOR_Blank=1;
		else if f2b_15_t = 'African' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Afro-Boricua-Taino Indian' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'American (all mixed up)' then SOR_nonHisp=1  ;	
		else if f2b_15_t = 'American race' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Anarchist' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Anglo-German' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Argentinian native' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Ashkeanzi' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Ashkenazi' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Asian American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Black American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Black white' then SOR_nonHisp=1  ;	
		else if f2b_15_t = 'Bosnia' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Brazilian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Brown' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Celtic' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Decline information' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Egyptian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'European American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'European-American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Finnish' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Franco-Latin (Rhenish Palatinate), Quebecois, Iberian Spanish' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'HUMAN' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Homo sapien' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Human' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Human' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Human race' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'IDK' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Idk' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Idk' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Indigenous' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Indigenous' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Indigenous Mexican' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Iranian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Irish' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Israeli' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Jewish' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Many races' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Mestiza' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Mestizo' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Middle Eastern' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Middle Eastern' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Middle Eastern American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Middle eastern' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Mixed' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Mixed' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Mixed American Born' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Mixed race' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Mixed race spanish/native Mexican' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Multi Racial' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Multi-Cultural' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Multiracial' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Native American' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Native American' then SOR_nonHisp=1  ;
		else if f2b_15_t = "Native American from mother and father's side." then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Nn' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'None' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Otaku' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Other' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Parsi Zoroastrian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Peruvian Indigenous' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Polish, Czechoslovakian, Scandinavian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Portuguese' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Refuse' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Russian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Salvadoran' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Scythian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Spanish Indian' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Syrian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'Taino' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Tepehuanes' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'Viking' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'West Indian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'White Irish Indian Japanese hawawiien' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'White or Caucasian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'armenian' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'dont know what to consider as race' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'human' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'human race' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'indigenous' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'jew' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'jewish' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'mestizo' then SOR_Hisp_Ind=1 ;
		else if f2b_15_t = 'middle Eastern' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'mixed' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'mixed race Japanese/Polish' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'n/a' then SOR_nonHisp=1  ;
		else if f2b_15_t = 'not important' then SOR_nonHisp=1  ;
		else if 	SOR_Blank= . and SOR_nonHisp=.
			and SOR_Hisp_Ind=. then SOR_Hisp=1;	
			end;
		
run;

proc freq data= sl_dat_backcode;
	where f2b_15_t ne "__NA__";
	table f2b_15_t*Hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind *SOR_Hisp/ list missing norow nocol;
	title "2020";
run;

proc freq data= sl_dat_backcode;
	where f2a_8_t ne "__NA__";
	table f2a_8_t*hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind *SOR_Hisp / list missing norow nocol;
	title "2030";
run;



proc freq data= sl_dat_backcode;
	where f2b_15_t ne "__NA__";
	table Hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind*SOR_Hisp / list missing norow nocol;
	title "2020";
run;

proc freq data= sl_dat_backcode;
	where f2a_8_t ne "__NA__";
	table hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind*SOR_Hisp / list missing norow nocol;
	title "2030";
run;

data qc3;
	set sl_dat_backcode;
	where hisp=0 and SOR_Hisp=1;
run; 

/*post back-coding out of SOR*/
proc freq data= sl_dat_backcode;
	where f2b_15_t ne "__NA__" and SOR=1;
	table Hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind*SOR_Hisp / list missing norow nocol;
	title "2020, post back-coding out of SOR";
run;

proc freq data= sl_dat_backcode;
	where f2a_8_t ne "__NA__" and SOR=1;
	table hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind*SOR_Hisp / list missing norow nocol;
	title "2030, post back-coding out of SOR";
run;

proc freq data= sl_dat_backcode;
	where f2a_8_t ne "__NA__" and SOR=1;
	table hisp*SOR_Blank* SOR_nonHisp*SOR_Hisp_Ind*SOR_Hisp*f2a_8_t / list missing norow nocol;
	title "2030, post back-coding out of SOR";
run;

